home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
dblrou1r
/
player.cls
< prev
next >
Wrap
Text File
|
1998-11-04
|
3KB
|
110 lines
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Player"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' A player class for the game Thang. Contains all of the variables and stuff a
' player object needs to do its thang! :)
Public m_hDC As Long
Public m_PosX As Long
Public m_PosY As Long
Public m_Color As Long
Public m_Player As Integer
Private m_VelX As Long
Private m_VelY As Long
Private m_Dir As Integer
Public Sub Create(hDC As Long, X As Long, Y As Long, Color As Long, PlayerNo As Integer)
m_hDC = hDC
m_PosX = X
m_PosY = Y
m_Color = Color
m_Player = PlayerNo
End Sub
Public Sub Move()
m_PosX = m_PosX + m_VelX
m_PosY = m_PosY + m_VelY
End Sub
Public Sub Draw()
For X = 0 To 2
For Y = 0 To 2
SetPixel m_hDC, m_PosX + X, m_PosY + Y, m_Color
ScrBufPut m_PosX + X, m_PosY + Y, m_Player
Next Y
Next X
End Sub
Public Sub ChangeDir(DIR)
Select Case DIR
Case DIR_UP:
If Not m_Dir = DIR_DOWN Then
m_VelY = VEL_UP
m_Dir = DIR_UP
End If
Case DIR_DOWN:
If Not m_Dir = DIR_UP Then
m_VelY = VEL_DOWN
m_Dir = DIR_DOWN
End If
Case DIR_LEFT:
If Not m_Dir = DIR_RIGHT Then
m_VelX = VEL_LEFT
m_Dir = DIR_LEFT
End If
Case DIR_RIGHT:
If Not m_Dir = DIR_LEFT Then
m_VelX = VEL_RIGHT
m_Dir = DIR_RIGHT
End If
Case DIR_STOPX:
m_VelX = VEL_NONE
Case DIR_STOPY:
m_VelY = VEL_NONE
Case DIR_NEWGAME:
m_Dir = DIR_NEWGAME
End Select
End Sub
Public Function Collision(OtherPlayer As Player) As Boolean
' If player has left the screen:
' Left
If m_PosX < 0 Then
Collision = True
Exit Function
End If
' Right
If m_PosX > (GetSystemMetrics(SM_CXSCREEN) - Form1.Frame1.Width) Then
Collision = True
Exit Function
End If
' Up
If m_PosY < 0 Then
Collision = True
Exit Function
End If
' Down
If m_PosY > GetSystemMetrics(SM_CYSCREEN) Then
Collision = True
Exit Function
End If
For X = 0 To 2
For Y = 0 To 2
' If player has hit other player's line
If ScrBufGet(m_PosX + X, m_PosY + Y) = OtherPlayer.m_Player Then
Collision = True
Exit Function
End If
Next Y
Next X
End Function